package gold.digger;

import gold.utils.InputUtil;

import java.util.Arrays;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC455 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int findContentChildren(int[] g, int[] s) {
            Arrays.sort(g);
            Arrays.sort(s);

            int satisfy = 0, i = s.length - 1, j = g.length - 1;
            while (i >= 0 && j >= 0) {
                if (s[i] >= g[j]) {
                    ++satisfy;
                    --i;
                    --j;
                } else {
                    --j;
                }
            }

            return satisfy;
        }
    }

    public void run() {
        Solution solution = new Solution();
        int[] g = InputUtil.toIntegerArray("[1,2,3]");
        int[] s = InputUtil.toIntegerArray("[1,1]");
        System.out.println(solution.findContentChildren(g, s));
    }

    public static void main(String[] args) throws Exception {
        LC455 an = new LC455();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
